//
//  AdsenceView.m
//  Adsense
//
//  Created by 퇴프 정윤원 on 10. 2. 11..
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "AdsenseView.h"
#import "SPUtility.h"

@implementation AdsenseViewController

- (AdsenseView *)adsenseView {
	return (AdsenseView *)self.view;
}

- (void) viewDidLoad {
	[super viewDidLoad];
	[[self adsenseView] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[SPUtility pathForResource:@"adsense.html"]]]];
}

@end

@implementation AdsenseDelegate

#pragma mark -
#pragma mark webView delegate

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
	static NSInteger count = 3;
	count--;
	if ( count>0 ) return YES;
	[[UIApplication sharedApplication] openURL:[request URL]];
	return NO;
}

@end


@implementation AdsenseView

- (void) dealloc {
	[[self delegate] release];
	[super dealloc];
}

+ (UIWebView *)adsenceByDefault {
	AdsenseView *adsense = [[[[AdsenseViewController alloc] initWithNibName:@"AdsenseView" bundle:nil] autorelease] adsenseView];
	adsense.delegate = [[AdsenseDelegate alloc] init];
	return adsense;
}

@end
